package cn.tedu.zhwy.information.service.impl;

import cn.tedu.zhwy.information.mapper.BuildingMapper;
import cn.tedu.zhwy.information.pojo.dto.BuildingQuery;
import cn.tedu.zhwy.information.pojo.dto.BuildingSaveParam;
import cn.tedu.zhwy.information.pojo.entity.Building;
import cn.tedu.zhwy.information.pojo.vo.BuildingVO;
import cn.tedu.zhwy.information.service.BuildingService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Slf4j
@Service
public class BuildingServiceImpl implements BuildingService {
    @Autowired
    private BuildingMapper buildingMapper;
    @Override
    public void saveBuilding(BuildingSaveParam buildingSaveParam) {
        Building building = new Building();
        BeanUtils.copyProperties(buildingSaveParam, building);
        if (building.getBid() == null) {
            buildingMapper.insert(building);
        }
        buildingMapper.update(building);
    }

    @Override
    public List<BuildingVO> selectBuilding(BuildingQuery buildingQuery) {
        List<BuildingVO> list = buildingMapper.select(buildingQuery);
        log.debug("楼座信息:list={}",list);
        return list;
    }

    @Override
    public void deleteBuilding(Long bid) {
        buildingMapper.delete(bid);
    }
}
